package com.letoken.platform.repo.mall.dao;

import com.letoken.platform.repo.dao.SpiceBaseMapper;
import com.letoken.platform.repo.helper.CalculateConsumerValue;
import com.letoken.platform.repo.mall.po.AppMallAmbSummary;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 推广大使分红 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-06-07
 */
public interface AppMallAmbSummaryMapper extends SpiceBaseMapper<AppMallAmbSummary> {

    @Select("SELECT * FROM app_mall_amb_summary WHERE DATE_FORMAT(ADDDATE(reward_time, INTERVAL count_down MINUTE), '%Y-%m-%d %H:%i:%s') <= NOW() and circulation_remain > 0")
    List<AppMallAmbSummary> getWaitRewardList();


    @Select("select * from app_mall_amb_summary where id = #{id} for update")
    AppMallAmbSummary selectForUpdate(@Param("id") Integer id);

    @Select("select * from app_mall_amb_summary where circulation_remain>0")
    List<AppMallAmbSummary> getIssueUserIdList();



    @Select("SELECT user_id ,ROUND(SUM(total_circulation),8) as amount  from app_mall_ambassador_record where create_time > #{date} group by user_id")
    List<CalculateConsumerValue.ObtainAssetPo> obtainAssetAmount(@Param("date") String date);


    @Select("SELECT ROUND(SUM(total_circulation),8)   from app_mall_ambassador_record where user_id = #{userId} and  create_time > #{date}")
    BigDecimal obtainAssetAmountUser(@Param("userId") Integer userId,@Param("date") String date);

}
